﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using Oracle.DataAccess;
using EntitiesLayer.Entities;
using System.Data;
using System.Data.OracleClient;

namespace DataLayer.DAO
{
   public class MenuDAO
    {
        private Connection.Connection cn;
        private OracleConnection objCn;

        public MenuDAO()
        {
            cn = new Connection.Connection();
            objCn = cn.Conecta();
        }


        public List<Menu> LisMenuPadres(int perfil)

            {
                List<Menu> lstObject = new List<Menu>();

                try
                {
                    OracleCommand cmd = new OracleCommand("MENUPADRE", objCn);
                    objCn.Open();
                    cmd.Connection = objCn;
                    cmd.CommandTimeout = 60;
                    cmd.CommandType = CommandType.StoredProcedure;
                    cmd.Parameters.Add(new OracleParameter("RECORDSET", OracleType.Cursor, 100,ParameterDirection.Output,null,DataRowVersion.Current,false,null));
                    cmd.Parameters.Add(new OracleParameter("v_id_perfil", OracleType.Int32, 10, ParameterDirection.Input, false, 10, 0, null, DataRowVersion.Current, perfil));
                     
                    using (IDataReader oRead = cmd.ExecuteReader(CommandBehavior.SingleResult))
                    {
                        if ( oRead != null ){
                            while (oRead.Read())
                            {
                                Menu oUser = new Menu();

                                if (!oRead.IsDBNull(oRead.GetOrdinal("IMEN_ID_MENU")))
                                {
                                    if (!string.IsNullOrEmpty(oRead.GetInt32(oRead.GetOrdinal("IMEN_ID_MENU")).ToString()))
                                    {
                                        oUser.IMEN_ID_MENU = oRead.GetInt32(oRead.GetOrdinal("IMEN_ID_MENU"));        
                                    }
                                }


                                if (!oRead.IsDBNull(oRead.GetOrdinal("IMEN_ID_MENU2")))
                                {
                                    if (!string.IsNullOrEmpty(oRead.GetInt32(oRead.GetOrdinal("IMEN_ID_MENU2")).ToString()))
                                    {
                                        oUser.IMEN_ID_MENU2 = oRead.GetInt32(oRead.GetOrdinal("IMEN_ID_MENU2"));
                                    }
                                }



                                if (!oRead.IsDBNull(oRead.GetOrdinal("IMEN_NOMBRE_MENU")))
                                {
                                    if (!String.IsNullOrEmpty(oRead.GetString(oRead.GetOrdinal("IMEN_NOMBRE_MENU"))))
                                    {
                                        oUser.IMEN_NOMBRE_MENU = oRead.GetString(oRead.GetOrdinal("IMEN_NOMBRE_MENU"));
                                    }
                                }

                                if (!oRead.IsDBNull(oRead.GetOrdinal("IMEN_RUTA_MENU")))
                                {
                                    if (!String.IsNullOrEmpty(oRead.GetString(oRead.GetOrdinal("IMEN_RUTA_MENU"))))
                                    {
                                        oUser.IMEN_RUTA_MENU = oRead.GetString(oRead.GetOrdinal("IMEN_RUTA_MENU"));
                                    }
                                }


                                if (!oRead.IsDBNull(oRead.GetOrdinal("IMEN_STYLE_MENU")))
                                {
                                    if (!String.IsNullOrEmpty(oRead.GetString(oRead.GetOrdinal("IMEN_STYLE_MENU"))))
                                    {
                                        oUser.IMEN_STYLE_MENU = oRead.GetString(oRead.GetOrdinal("IMEN_STYLE_MENU"));
                                    }
                                }

                                
                                lstObject.Add(oUser);
                                oUser = null;
                               }
                        } 
                    }
                                                                               
                }catch (Exception ex){
                    objCn.Dispose();
                }finally{
                    objCn.Close();
                }

                return lstObject;
           
        }


        public List<Menu> LisMenuHijos(int perfil,int codigo)

            {
                List<Menu> lstObject = new List<Menu>();

                try
                {
                    OracleCommand cmd = new OracleCommand("MENUHIJOP", objCn);
                    objCn.Open();
                    cmd.Connection = objCn;
                    cmd.CommandTimeout = 60;
                    cmd.CommandType = CommandType.StoredProcedure;
                    cmd.Parameters.Add(new OracleParameter("RECORDSET", OracleType.Cursor, 100,ParameterDirection.Output,null,DataRowVersion.Current,false,null));
                    cmd.Parameters.Add(new OracleParameter("v_id_perfil", OracleType.Int32, 10, ParameterDirection.Input, false, 10, 0, null, DataRowVersion.Current, perfil));
                    cmd.Parameters.Add(new OracleParameter("v_id_hijop", OracleType.Int32, 10, ParameterDirection.Input, false, 10, 0, null, DataRowVersion.Current, codigo));
                                         
                    using (IDataReader oRead = cmd.ExecuteReader(CommandBehavior.SingleResult))
                    {
                        if ( oRead != null ){
                            while (oRead.Read())
                            {
                                Menu oUser = new Menu();

                                if (!oRead.IsDBNull(oRead.GetOrdinal("IMEN_ID_MENU")))
                                {
                                    if (!string.IsNullOrEmpty(oRead.GetInt32(oRead.GetOrdinal("IMEN_ID_MENU")).ToString()))
                                    {
                                        oUser.IMEN_ID_MENU = oRead.GetInt32(oRead.GetOrdinal("IMEN_ID_MENU"));        
                                    }
                                }


                                if (!oRead.IsDBNull(oRead.GetOrdinal("IMEN_ID_MENU2")))
                                {
                                    if (!string.IsNullOrEmpty(oRead.GetInt32(oRead.GetOrdinal("IMEN_ID_MENU2")).ToString()))
                                    {
                                        oUser.IMEN_ID_MENU2 = oRead.GetInt32(oRead.GetOrdinal("IMEN_ID_MENU2"));
                                    }
                                }

                                
                                if (!oRead.IsDBNull(oRead.GetOrdinal("IMEN_NOMBRE_MENU")))
                                {
                                    if (!String.IsNullOrEmpty(oRead.GetString(oRead.GetOrdinal("IMEN_NOMBRE_MENU"))))
                                    {
                                        oUser.IMEN_NOMBRE_MENU = oRead.GetString(oRead.GetOrdinal("IMEN_NOMBRE_MENU"));
                                    }
                                }

                                if (!oRead.IsDBNull(oRead.GetOrdinal("IMEN_RUTA_MENU")))
                                {
                                    if (!String.IsNullOrEmpty(oRead.GetString(oRead.GetOrdinal("IMEN_RUTA_MENU"))))
                                    {
                                        oUser.IMEN_RUTA_MENU = oRead.GetString(oRead.GetOrdinal("IMEN_RUTA_MENU"));
                                    }
                                }

                                if (!oRead.IsDBNull(oRead.GetOrdinal("IMEN_STYLE_MENU")))
                                {
                                    if (!String.IsNullOrEmpty(oRead.GetString(oRead.GetOrdinal("IMEN_STYLE_MENU"))))
                                    {
                                        oUser.IMEN_STYLE_MENU = oRead.GetString(oRead.GetOrdinal("IMEN_STYLE_MENU"));
                                    }
                                }

                                lstObject.Add(oUser);
                                oUser = null;
                               }
                        } 
                    }
                                                                               
                }catch (Exception ex){
                    objCn.Dispose();
                }finally{
                    objCn.Close();
                }

                return lstObject;
           
        }


        public List<Combos> ListarTipoQueja(string codigo)

            {
                List<Combos> lstObject = new List<Combos>();

                try
                {
                    OracleCommand cmd = new OracleCommand("LISTADO_TIPO_QUEJA", objCn);
                    objCn.Open();
                    cmd.Connection = objCn;
                    cmd.CommandTimeout = 60;
                    cmd.CommandType = CommandType.StoredProcedure;
                    cmd.Parameters.Add(new OracleParameter("RECORDSET", OracleType.Cursor, 100,ParameterDirection.Output,null,DataRowVersion.Current,false,null));
                    cmd.Parameters.Add(new OracleParameter("RQUE_COD_TIP_QUE", OracleType.VarChar, 10, ParameterDirection.Input, false, 10, 0, null, DataRowVersion.Current, codigo));
                    

                    using (IDataReader oRead = cmd.ExecuteReader(CommandBehavior.SingleResult))
                    {
                        if ( oRead != null ){
                            while (oRead.Read())
                            {
                                Combos oCombos = new Combos();

                                if (!oRead.IsDBNull(oRead.GetOrdinal("IQUE_PLAZO_CANTIDAD")))
                                {
                                    if (!string.IsNullOrEmpty(oRead.GetInt32(oRead.GetOrdinal("IQUE_PLAZO_CANTIDAD")).ToString()))
                                    {
                                        oCombos.IQUE_PLAZO_CANTIDAD = oRead.GetInt32(oRead.GetOrdinal("IQUE_PLAZO_CANTIDAD"));
                                    }
                                }

 
                                lstObject.Add(oCombos);
                                oCombos = null;
                               }
                        } 
                    }
                                                                               
                }catch (Exception ex){
                    objCn.Dispose();
                }finally{
                    objCn.Close();
                }

                return lstObject;
           
        }

       


    }
}
